﻿using BW.Demo.Domain.Entities;
using BW.Demo.ErrorCode;
using BW.Demo.Infrastructure.Interfcaes;
using BW.Demo.WebApi.Applications.Commands.Deputy;
using MediatR;

namespace BW.Demo.WebApi.Applications.CommandHandlers.Deputy
{
    
    public class PicQueryCommandHandler : IRequestHandler<PicQueryCommand, APIResult<List<PictureInformation>>>
    {
        IBaseRespitory<PictureInformation> _respitory;
        public PicQueryCommandHandler(IBaseRespitory<PictureInformation> _respitory)
        {
            this._respitory = _respitory;
        }
        public Task<APIResult<List<PictureInformation>>> Handle(PicQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<PictureInformation>> result = new APIResult<List<PictureInformation>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();
            var list = _respitory.GetAll().Where(x => x.Batch == request.Batch);
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
